<template>
  <tl-sub-page :render="render" :modal-append-to-body="true" :append-to-body="true" :visible.sync="visible" v-dialogDrag :title="title" :close-on-click-modal="false" class="tl-dialog" width="1000px" @open="open" @close="close">
    <el-form class="tl-form" ref="form" :model="model" :rules="rules" label-width="150px" :disabled="disableEditSubmit || disableSave">
      <el-row>
        <el-col :span="12">
          <el-form-item label="督办单名称" prop="supervisename" :rules="rules.validateRequire">
            <el-input v-model="model.supervisename"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="督办单编号" prop="supervisecode">
            <el-input v-model="model.supervisecode" :disabled="true" placeholder="系统自动赋值"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="督办对象类型" prop="superviseobjecttype" :rules="rules.validateRequire">
            <el-select v-model="model.superviseobjecttype" filterable clearable placeholder="请选择督办类型">
              <el-option v-for="item in codeModel.superviseobjecttypeList" :key="item.code" :label="item.name" :value="item.code" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="督办对象" prop="superviseobject" :rules="rules.validateRequire" v-if="milepostvisible">
            <el-input v-model="model.superviseobject" :disabled="true" class="tl-ref-selector">
              <el-button slot="append" type="primary" icon="el-icon-search"></el-button>
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="督办对象" prop="superviseobject" :rules="rules.validateRequire" v-if="taskvisible">
            <el-input v-model="model.dispsuperviseobject" :disabled="true"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="督办对象" prop="dispsuperviseobject" :rules="rules.validateRequire" v-if="projectVisible">
            <el-input v-model="model.superviseobject" :disabled="true"> </el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="责任人" prop="responsiblename" :rules="rules.validateRequire">
            <tl-ref-user v-model="model.responsiblename" :initDisplayData.sync="model.responsiblename" dataType="code" :singleSelect="true" @ckick="userConfirm"></tl-ref-user>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="督办期限" prop="superviseperiod">
            <el-date-picker v-model="model.superviseperiod" type="date" value-format="yyyy-MM-dd"></el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="督办原因" prop="supervisereason" :rules="rules.validateRequire">
            <el-input v-model="model.supervisereason" type="textarea" :rows="4"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="督办响应" prop="superviseresponse">
            <el-input v-model="model.superviseresponse" type="textarea" :rows="4"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="督办部门" prop="supervisedeptname">
            <el-input v-model="model.supervisedeptname" :disabled="true"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="督办发起人" prop="supervisepeople">
            <el-input v-model="model.supervisepeople" :disabled="true"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="督办状态" prop="supervisestate">
            <el-select v-model="model.supervisestate" filterable clearable>
              <el-option v-for="item in codeModel.supervisestateList" :key="item.code" :label="item.name" :value="item.code" />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="备注" prop="description">
            <el-input v-model="model.description" type="textarea" :rows="4"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <div class="tl-form-line-title">
        【单据】申请信息
      </div>
      <el-row>
        <el-col :span="12">
          <el-form-item label="申请部门" prop="applydeptname">
            <tl-ref-dept v-model="model.applydeptcode" :initDisplayData.sync="model.applydeptname" :disabled="true" dataType="code" nameType="fullname" :singleSelect="true" :externalQueryParam="{ qry_enabled: 1 }"></tl-ref-dept>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="申请公司" prop="applyorgname">
            <el-input v-model="model.applyorgname" :readonly="true" class="is-disabled"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="申请人姓名" prop="applyusername">
            <tl-ref-user v-model="model.applyusername" :initDisplayData.sync="model.applyusername" :disabled="true" dataType="code" :singleSelect="true"></tl-ref-user>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="申请人工号" prop="applyusercode">
            <el-input v-model="model.applyusercode" :readonly="true" class="is-disabled"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="单据日期" prop="docdate">
            <el-date-picker v-model="model.docdate" type="date" :disabled="true" placeholder="单据日期" value-format="yyyy-MM-dd"></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="提交时间" prop="submitdate">
            <el-date-picker v-model="model.submitdate" type="date" placeholder="提交时间" value-format="yyyy-MM-dd" disabled></el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <tl-approval-history ref="history" sourceType="GpmProjectSupervise" :sourceId="model.id" />
    <div slot="footer" class="dialog-footer">
      <tl-attachment sourceType="GpmProjectSupervise" :sourceId="model.id" :disabled="disableAttachment" :editable="stateEdit"></tl-attachment>
      <el-button type="primary" @click="$refs.history.visible = true" :disabled="disableApprovalHistory"> <svg-icon icon-class="list" />审批历史 </el-button>
    </div>
    <tlsdProject-milepost-ref ref="sdProjectMilepostRef" :isSingleSelect="true" :externalQueryParam="externalQueryParamForMilepost"> </tlsdProject-milepost-ref>
  </tl-sub-page>
</template>

<script>
/** mixins */
import { mixin_approval_edit } from '@tapui/mixins/mixin_approval_edit'
/** 子组件 */
import tlsdProjectMilepostRef from '@/views/gpm/gpmProjectMilepost/refList'
/** 工具类 */
import { putAction, getAction, postAction, deleteAction } from '@tapui/utils/http'
/** VUE配置 */
export default {
  mixins: [mixin_approval_edit],
  components: { tlsdProjectMilepostRef },
  data() {
    return {
      moduleTitle: '项目督办',
      urlPrefix: '/sd/projectSupervise/',
      milepostvisible: true,
      taskvisible: false,
      projectVisible: false,
      externalQueryParamForTask: {},
      externalQueryParamForMilepost: {},
      url: {
        // 额外的url
      }
    }
  },
  props: {
    projectinfo: {}
  },
  methods: {
    /** 获取里程碑参照数据 */
    getSdProjectMilepostData(selectionRow, selectKey, selectionValue) {
      this.$set(this.model, 'superviseobject', selectionRow.milepostname)
      this.$set(this.model, 'superviseobjectcode', selectionRow.milepostcode)
      // 里程碑赋值责任人
      this.$set(this.model, 'responsiblecode', selectionRow.responsiblecode)
      this.$set(this.model, 'responsiblename', selectionRow.responsible)
    },
    assignDefaultValue() {
      if (this.isAdd) {
        if (this.codeModel.flowidList && this.codeModel.flowidList.length > 0) {
          this.$set(this.model, 'flowid', parseInt(this.codeModel.flowidList[0].id))
        }
        let a = this.projectinfo
        this.$set(this.model, 'orgcode', this.org.code)
        this.$set(this.model, 'disporgcode', this.org.name)
        this.$set(this.model, 'applyorgcode', this.org.code)
        this.$set(this.model, 'applyorgname', this.org.name)
        this.$set(this.model, 'deptcode', this.dept.code)
        this.$set(this.model, 'deptname', this.dept.fullname)
        this.$set(this.model, 'applydeptcode', this.dept.code)
        this.$set(this.model, 'applydeptname', this.dept.fullname)
        // 督办部门信息
        this.$set(this.model, 'supervisedeptcode', this.dept.code)
        this.$set(this.model, 'supervisedeptname', this.dept.fullname)
        // 督办发起人信息
        this.$set(this.model, 'supervisepeoplecode', this.user.code)
        this.$set(this.model, 'supervisepeople', this.user.name)
        // 督办状态
        this.$set(this.model, 'supervisestate', '0')
        this.$set(this.model, 'usercode', this.user.code)
        this.$set(this.model, 'username', this.user.name)
        this.$set(this.model, 'applyusercode', this.user.code)
        this.$set(this.model, 'applyusername', this.user.name)
        this.$set(this.model, 'docdate', new Date())
        // 督办期限为3天
        var date = new Date()
        date.setDate(date.getDate() + 2)
        this.$set(this.model, 'superviseperiod', date)
      }
    },
    loaded() {
      // 页面加载完毕执行
      if (this.model.superviseobjecttype === '0') {
        this.milepostvisible = false
        this.taskvisible = true
        this.projectVisible = false
      } else if (this.model.superviseobjecttype === '1') {
        this.milepostvisible = true
        this.taskvisible = false
      }
    },
    userConfirm(selectionRow) {
      this.$set(this.model, 'responsiblecode', selectionRow[0].code)
      this.$set(this.model, 'responsiblename', selectionRow[0].name)
    }
  }
}
</script>
